home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byt0187b.arc / LISTINGS.DOC < prev    next >
Text File  |  1986-10-28  |  6KB  |  267 lines

  1.  
  2.     program filewrite;
  3.     { UCSD Pascal program to write a 64K data file }
  4.     { in 512 chunks of 128 bytes each              }
  5.  
  6.     const
  7.         CHUNK_SIZE = 128;        { size of chunks in bytes }
  8.         N_CHUNKS = 512;        { number of chunks to write }
  9.  
  10.     type
  11.         chunk_array = packed array [1..CHUNK_SIZE] of char;
  12.         chunk_file = file of chunk_array;
  13.  
  14.     var
  15.         chunk : chunk_array;    { one chunk }
  16.         cf : chunk_file;        { file variable for data file }
  17.         i : integer;            { loop control variable }
  18.  
  19.     begin { filewrite }
  20.         for i := 1 to CHUNK_SIZE do
  21.             chunk[i] := chr(ord('1') + (i - 1) mod 8);
  22.         rewrite(cf, 'TEST');
  23.         for i := 1 to N_CHUNKS do begin
  24.             cf^ := chunk;
  25.             put(cf)
  26.         end;
  27.         close(cf, LOCK)
  28.     end.
  29.  
  30.  
  31. Listing 1
  32. UCSD Pascal 64Kbyte File╨writing Benchmark
  33.     program fileread;
  34.     { UCSD Pascal program to read a 64K data file }
  35.     { in 512 chunks of 128 bytes each             }
  36.  
  37.     const
  38.         CHUNK_SIZE = 128;        { size of chunks in bytes }
  39.         N_CHUNKS = 512;        { number of chunks to read }
  40.  
  41.     type
  42.         chunk_array = packed array [1..CHUNK_SIZE] of char;
  43.         chunk_file = file of chunk_array;
  44.  
  45.     var
  46.         chunk : chunk_array;    { one chunk }
  47.         cf : chunk_file;        { file variable for data file }
  48.         i : integer;            { loop control variable }
  49.  
  50.     begin { fileread }
  51.         reset(cf, 'TEST');
  52.         chunk := cf^;
  53.         for i := 2 to N_CHUNKS do begin
  54.             get(cf);
  55.             chunk := cf^;
  56.         end;
  57.         close(cf)
  58.     end.
  59.  
  60.  
  61. Listing 2
  62. UCSD Pascal 64Kbyte File╨reading Benchmark
  63.     program calculations;
  64.     { UCSD Pascal program to perform series of real }
  65.     { multiplications and divisions }
  66.  
  67.     const
  68.         MAX = 5000;    { number of repetitions }
  69.  
  70.     var
  71.         a, b, c : real;    { used in calculations }
  72.         i : integer;        { loop control variable }
  73.  
  74.     begin { calculations }
  75.         a := 2.71828;
  76.         b := 3.14159;
  77.         c := 1.0;
  78.         for i := 1 to MAX do begin
  79.             c := c * a;
  80.             c := c * b;
  81.             c := c / a;
  82.             c := c / b
  83.         end;
  84.         writeln('Error : ', c - 1.0)
  85.     end.
  86.  
  87. Listing 3
  88. UCSD Pascal Calculation Benchmark
  89.     program sieve;
  90.     { UCSD Pascal Sieve of Eratosthenes Benchmark }
  91.  
  92.     const
  93.         SIZE = 7000;        { size of array for standard benchmark }
  94.  
  95.     var
  96.         flags : array [0..SIZE] of Boolean;
  97.         i, prime, k, count, iter: integer;
  98.  
  99.     begin { sieve }
  100.         writeln('10 iterations');
  101.         for iter := 1 to 10 do begin
  102.             count := 0;
  103.             for i := 0 to SIZE do
  104.                 flags[i] := TRUE;
  105.             for i := 0 to SIZE do
  106.                 if flags[i] then begin
  107.                     prime := i + i + 3;
  108.                     k := i + prime;
  109.                     while k <= SIZE do begin
  110.                         flags[k] := FALSE;
  111.                         k := k + prime
  112.                     end;
  113.                     count := count + 1
  114.                 end
  115.         end;
  116.         writeln(count, ' primes')
  117.     end.
  118.  
  119. Listing 4
  120. UCSD Pascal Sieve of Eratosthenes Benchmark
  121. MODULE filewrite;
  122.  
  123. FROM Files IMPORT
  124.     FILE, FileState, Create, Close, WriteBytes;
  125.  
  126. FROM SYSTEM IMPORT
  127.     ADR;
  128.  
  129. CONST
  130.     CHUNKSIZE = 128;   (* size of chunks in bytes *)
  131.     NCHUNKS = 512;     (* number of chunks to write *)
  132.  
  133. TYPE
  134.     chunkarray = ARRAY [1..CHUNKSIZE] OF CHAR;
  135.  
  136. VAR
  137.     chunk : chunkarray;           (* one chunk *)
  138.     cf : FILE;                    (* chunk file variable *)
  139.     i : CARDINAL;                 (* loop control variable *)
  140.     junk : CARDINAL;              (* status from WriteBytes *)
  141.     fs : FileState;               (* status from Create/Close *)
  142.     name : ARRAY [0..30] OF CHAR;    (* file name *)
  143.  
  144. BEGIN
  145.     FOR i := 1 TO CHUNKSIZE DO
  146.         chunk[i] := CHR(ORD('1') + (i - 1) MOD 8)
  147.     END;
  148.     name := "TEST.DATA";
  149.     fs := Create(cf, name);
  150.     FOR i := 1 TO NCHUNKS DO
  151.         junk := WriteBytes(cf, ADR(chunk), CHUNKSIZE)
  152.     END;
  153.     fs := Close(cf)
  154. END filewrite.
  155.  
  156. Listing 5
  157. Modula╨2 64Kbyte File Writing Benchmark
  158.  
  159. MODULE fileread;
  160.  
  161. FROM Files IMPORT
  162.     FILE, FileState, Open, Close, ReadBytes;
  163.  
  164. FROM SYSTEM IMPORT
  165.     ADR;
  166.  
  167. CONST
  168.     CHUNKSIZE = 128;   (* size of chunks in bytes *)
  169.     NCHUNKS = 512;     (* number of chunks to write *)
  170.  
  171. TYPE
  172.     chunkarray = ARRAY [1..CHUNKSIZE] OF CHAR;
  173.  
  174. VAR
  175.       chunk : chunkarray;            (* one chunk *)
  176.       cf : FILE;                    (* chunk file variable *)
  177.       i : CARDINAL;                (* loop control variable *)
  178.       junk : CARDINAL;                (* status from ReadBytes *)
  179.       fs : FileState;                (* status from Open & Close *)
  180.       name : ARRAY [0..30] OF CHAR;    (* file name *)
  181.  
  182. BEGIN
  183.     name := "TEST.DATA";
  184.     fs := Open(cf, name);
  185.     FOR i := 1 TO NCHUNKS DO
  186.         junk := ReadBytes(cf, ADR(chunk), CHUNKSIZE)
  187.     END;
  188.     fs := Close(cf);
  189. END fileread.
  190.  
  191. Listing 6
  192. Modula╨2 64Kbyte File Reading Benchmark
  193.  
  194. MODULE calculations;
  195. (* Modula╨2 program to perform a series of real *)
  196. (* multiplications and divisions *)
  197.  
  198. FROM RealInOut IMPORT
  199.     WriteReal;
  200.  
  201. FROM InOut IMPORT
  202.     WriteString, WriteLn;
  203.  
  204. CONST
  205.     MAX = 5000;         (* number of iterations *)
  206.  
  207. VAR
  208.     a, b, c : REAL;     (* used in calculations *)
  209.     i : CARDINAL;       (* loop control variable *)
  210.  
  211. BEGIN
  212.     a := 2.71828;
  213.     b := 3.14159;
  214.     c := 1.0;
  215.     FOR i := 1 TO MAX DO
  216.         c := c * a;
  217.         c := c * b;
  218.         c := c / a;
  219.         c := c / b
  220.     END;
  221.     WriteString('Error = ');
  222.     WriteReal(c - 1.0, 10);
  223.     WriteLn
  224. END calculations.
  225.  
  226. Listing 7
  227. Modula╨2 Real Calculations Benchmark
  228. MODULE sieve;
  229.  
  230. FROM InOut IMPORT
  231.     WriteLn, WriteString, WriteCard;
  232.  
  233. CONST
  234.     SIZE = 7000;
  235.  
  236. VAR
  237.     flags : ARRAY [0..SIZE] OF BOOLEAN;
  238.     i, prime, k, count, iter : CARDINAL;
  239.  
  240. BEGIN
  241.     WriteString('10 iterations');
  242.     FOR iter := 1 TO 10 DO
  243.         count := 0;
  244.         FOR i := 0 TO SIZE DO
  245.             flags[i] := TRUE
  246.         END;
  247.         FOR i := 0 TO SIZE DO
  248.             IF flags[i] THEN
  249.                 prime := i + i + 3;
  250.                 k := i + prime;
  251.                 WHILE k <= SIZE DO
  252.                     flags[k] := FALSE;
  253.                     k := k + prime
  254.                 END;
  255.                 INC(count)
  256.             END
  257.         END
  258.     END;
  259.     WriteCard(count, 1);
  260.     WriteString(' primes');
  261.     WriteLn
  262. END sieve.
  263.  
  264. Listing 8
  265. Modula╨2 Sieve of Eratosthenes Benchmark
  266. Program Benchmarks
  267.